var t = getApp(), e = t.requirejs('core');
Page({
  data: {
    all_goods_priceta: '',
    navs: 1,
    page: 1,
    list: [],
    navindex: 1,
    isnomarlc:0
  },
  onLoad (options) {
    t.checkAuth(),e.get("member/repertory", {}, res => {
      console.log(res);
      this.setData({isnomarl:res.isnomarl,all_credit2: res.all_credit2,all_goods_price: res.all_goods_price,month_sum_rkcounts: res.month_sum_rkcounts,month_sum_ckcounts: res.month_sum_ckcounts});
      if(res.isnomarl==0){
        let that = this;
        that.setData({
          isnomarlc:1
        })
        wx.showModal({
          title: "无法访问",
          content: "您好，升级总代才可开放使用权限，详情请咨询客服！",
          success: function(t) {
            if (t.confirm) {
              wx.switchTab({
                  url: '/pages/index/index',
              })
            } else if (t.cancel) {
              wx.switchTab({
                  url: '/pages/index/index',
              })
            }
          }
        })
      }
    })
    this.get_add();
  },
    // 切换导航
    changenav(params) {
      this.setData({navs: params.currentTarget.dataset.index, page: 1});
      if (this.data.navs == 1) {
        this.get_add()
      } else if (this.data.navs == 2) {
        this.get_sub()
      }
    }, // 获取增加数据
    get_add () {
      let that = this;
      e.get('zstock/kucun/get_list', {page: that.data.page, type: 1}, res => {
        console.log("增加数据");
        console.log(res)
        let list = [];
        if (that.data.page != 1) {
          list = that.data.list
        }
        res.list.forEach(item => {
          list.push(item)
        });
        this.setData({list: list});
      })
    },// 获取减少数据
    get_sub () {
      let that = this;
      e.get('zstock/kucun/get_list', {page: that.data.page, type: 2}, res => {
        console.log("减少数据");
        console.log(res)
        let list = [];
        if (that.data.page != 1) {
          list = that.data.list
        }
        res.list.forEach(item => {
          list.push(item)
        });
        this.setData({list: list});
      })
    },  // 下拉刷新
    onPullDownRefresh () {
      this.setData({page: 1});
      if (this.data.navs == 1) {this.get_add()} else {this.get_sub()}
      wx.showToast({title: '刷新完毕', icon: 'none'});
      wx.stopPullDownRefresh();
    },
    // 上拉加载
    onReachBottom () {
      this.setData({page: this.data.page + 1});
      if (this.data.navs == 1) {this.get_add()} else {this.get_sub()}
    },

})